package com.cynteka.cyfoman.core.config;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * User: Sergey
 * Date: 05.08.11
 * Time: 12:55
 */
public class JAXBLoader {
    public <T> T loadXML(Class<T> cls, String fileName) throws JAXBException, FileNotFoundException {
        JAXBContext context = JAXBContext.newInstance(cls);
        FileInputStream fis = new FileInputStream(fileName);
        Unmarshaller um = context.createUnmarshaller();
        T res = (T) um.unmarshal(fis);
        return res;
    }

}
